package com.qinghuan.threads.chapterOne;

/**
 * @Author: dubao
 * @Date: 2022/5/17 18:56
 * @Description:
 * 等待某几件事情完成以后才能继续往下执行，
 * 比如多个线程加载资源，需要等待多个线程全部加载完毕再汇总处理
 */
public class Test1_4_1 {

    public static void main(String[] args) throws InterruptedException {
        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("child threadOne over!");
            }
        });

        Thread threadTwo = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("child threadTwo over!");
            }
        });
        //启动子线程
        threadOne.start();
        threadTwo.start();
        System.out.println("wait all child thread over!");
        //等待子线程执行完毕，返回
        threadOne.join();
        threadTwo.join();
        System.out.println("all child thread over!");
    }

}
